<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import = "org.json.simple.*, java.util.ArrayList, java.util.TreeMap, org.owasp.encoder.Encode" %>
<%@ page import = "com.mbbmap.security.dao.*" %>
<%@ include file="/jsp/map/include/user-dao.jsp" %>	
<%@page import="com.mbbmap.util.EncryptionHelper"%>
<%

TreeMap<String, String> search = (TreeMap<String, String>) request.getAttribute("search");

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:include page="/jsp/map/include/html-meta.jsp" />
<title>MAYBANK</title>
<script src="<%= request.getContextPath() %>/js/report.js"></script>
</head>

<body onload="report.region_sla_init();">

<!-- Header -->
<%@ include file="/jsp/common/Header.jsp" %>	
<!-- End Header -->


<div class="row-fluid page" style="width:1200px; max-width:none;">
	<div class="span12">
		
		<jsp:include page="/jsp/map/include/report-nav.jsp">
			<jsp:param name="report_title" value='<%=EncryptionHelper.encrypt("Terminal Installation Report") %>' />
		</jsp:include>

		<form name="search_form" method="post" action="<%= request.getContextPath() + "/Report.do?dispatch=terminal_installation" %>" onsubmit="return report.search_region_sla_validate();">
			<div class="row-fluid form-horizontal search">
				<div class="span6">
				
					<div class="control-group">
						<label class="control-label">Period</label>
						<div class="controls">
							<input type="text" id="from_date" name="from_date" placeholder="eg. 23/01/2015" value="<%=search.containsKey("from_date") ? search.get("from_date") : "" %>" style="width:88px" /> to
							<input type="text" id="to_date" name="to_date" placeholder="eg. 09/02/2015" value="<%=search.containsKey("to_date") ? search.get("to_date") : "" %>" style="width:88px" />
						</div>
					</div>
					
					<div class="control-group">
						<label class="control-label">Month</label>
						<div class="controls">
							<select id="month" name="month" style="width:115px">
							<% 
								String html = "<option value=\"\"></option>"
									+ "<option value=\"01\">January</option>"
									+ "<option value=\"02\">February</option>"
									+ "<option value=\"03\">March</option>"
									+ "<option value=\"04\">April</option>"
									+ "<option value=\"05\">May</option>"
									+ "<option value=\"06\">June</option>"
									+ "<option value=\"07\">July</option>"
									+ "<option value=\"08\">August</option>"
									+ "<option value=\"09\">September</option>"
									+ "<option value=\"10\">October</option>"
									+ "<option value=\"11\">November</option>"
									+ "<option value=\"12\">December</option>";
								
								if(search.containsKey("month") && search.get("month").length() > 0){
									html = html.replace("value=\"" + search.get("month") + "\"", "value=\"" + search.get("month") + "\" selected ");
								}
								
								out.println(html);
							%>
							</select>
							
							<input type="text" id="year" name="year" placeholder="eg. 2015" value="<%=search.containsKey("year") ? search.get("year") : "" %>" style="width:88px" />
						</div>
					</div>
					
				</div>
				
				<div class="span6">
				
					
					
				</div>
			</div>
			
			<div class="row-fluid">
				<div class="span12 btn-control search">
					<button id="search_submit" name="search_submit" type="submit" class="btn">Search</button>
					<button id="search_clear" name="search_clear" type="submit" class="btn">Clear</button>
					<button id="export_submit" name="export_submit" type="submit" class="btn">Export Data</button>
				</div>
			</div>
			
		</form>
		
		<div style="width:1200px; overflow-x:auto">
		<table class="tblDetails reportTbl"><thead>
			<tr>
				<th rowspan="3">No.</th>
				<th rowspan="3">MAP Reference No.</th>
				<th rowspan="3">Vendor</th>
				<th rowspan="3">Area</th>
				<th rowspan="3">Job Type</th>
				<th rowspan="3">Stock</th>
				<th rowspan="3">Creator</th>
				<th rowspan="3">Date Request Sent</th>
				<th rowspan="3">Date Installed / Completed</th>
				<th rowspan="3">SLA</th>
				<th rowspan="3">Reschedule Date</th>
				<th rowspan="3">Status</th>
				<th rowspan="3">Wireless</th>
				<th rowspan="3">DEBIT</th>
				<th rowspan="3">Merchant Name</th>
				<th rowspan="3">Address 1</th>
				<th rowspan="3">Address 2</th>
				<th rowspan="3">Address 3</th>
				<th rowspan="3">AMEX POS</th>
				<th rowspan="3">AMEX MOTO</th>
				<th rowspan="3">DINERS</th>
				<th rowspan="3">GENTING</th>
				<th rowspan="3">AEON</th>
				<th rowspan="2" colspan="2">POS</th>
				<th colspan="16">EZYPAY - NORMAL</th>
				<th colspan="16">EZYPAY - AMEX</th>
				<th colspan="4">Acceptance</th>
				<th colspan="3">Others</th>
				<th colspan="5">Hotel Function</th>
				<th rowspan="3">Vendor Remark</th>
			</tr>
			<tr>
				<th colspan="2">3MTH</th>
				<th colspan="2">6MTH</th>
				<th colspan="2">9MTH</th>
				<th colspan="2">12MTH</th>
				<th colspan="2">18MTH</th>
				<th colspan="2">24MTH</th>
				<th colspan="2">30MTH</th>
				<th colspan="2">36MTH</th>
				<th colspan="2">3MTH</th>
				<th colspan="2">6MTH</th>
				<th colspan="2">9MTH</th>
				<th colspan="2">12MTH</th>
				<th colspan="2">18MTH</th>
				<th colspan="2">24MTH</th>
				<th colspan="2">30MTH</th>
				<th colspan="2">36MTH</th>
				<th rowspan="2">UPI</th>
				<th rowspan="2">ORS</th>
				<th rowspan="2">DCC</th>
				<th rowspan="2">WAVE</th>
				<th rowspan="2">ECR Cable</th>
				<th rowspan="2">Cash Advance</th>
				<th rowspan="2">Cash Back</th>
				<th rowspan="2">Card Verify</th>
				<th rowspan="2">Offline</th>
				<th rowspan="2">Manual Key-In</th>
				<th rowspan="2">Tips</th>
				<th rowspan="2">Refund</th>
			</tr>
			<tr>
				<th>TID</th>
				<th>MID</th>
				<th>TID</th>
				<th>MID</th>
				<th>TID</th>
				<th>MID</th>
				<th>TID</th>
				<th>MID</th>
				<th>TID</th>
				<th>MID</th>
				<th>TID</th>
				<th>MID</th>
				<th>TID</th>
				<th>MID</th>
				<th>TID</th>
				<th>MID</th>
				<th>TID</th>
				<th>MID</th>
				<th>TID</th>
				<th>MID</th>
				<th>TID</th>
				<th>MID</th>
				<th>TID</th>
				<th>MID</th>
				<th>TID</th>
				<th>MID</th>
				<th>TID</th>
				<th>MID</th>
				<th>TID</th>
				<th>MID</th>
				<th>TID</th>
				<th>MID</th>
				<th>TID</th>
				<th>MID</th>
				
			</tr>
		</thead><tbody>
		<%
		int n = 0;
		for(TreeMap<String, String> r : (ArrayList<TreeMap<String, String>>) request.getAttribute("rArr")){
			JSONArray addrObj = new JSONArray();
			if(r.get("address") != null) {
				addrObj = (JSONArray) JSONValue.parse(r.get("address"));
			}
			
			JSONObject partnerObj = new JSONObject();
			if(r.get("partners") != null) {
				partnerObj = (JSONObject) JSONValue.parse(r.get("partners"));
			}
			
			JSONObject ezpayObj = new JSONObject();
			if(r.get("ezpay") != null) {
				ezpayObj = (JSONObject) JSONValue.parse(r.get("ezpay"));
			}
			
			JSONObject ezpayAmexObj = new JSONObject();
			if(r.get("ezpay_amex") != null) {
				ezpayAmexObj = (JSONObject) JSONValue.parse(r.get("ezpay_amex"));
			}
			
			JSONObject acceptanceObj = new JSONObject();
			if(r.get("acceptance") != null) {
				acceptanceObj = (JSONObject) JSONValue.parse(r.get("acceptance"));
			}
			
			JSONObject otherObj = new JSONObject();
			if(r.get("others") != null) {
				otherObj = (JSONObject) JSONValue.parse(r.get("others"));
			}
			
			JSONObject hotelFunctionObj = new JSONObject();
			if(r.get("hotel_function") != null) {
				hotelFunctionObj = (JSONObject) JSONValue.parse(r.get("hotel_function"));
			}
			
			html = "<tr>"
				+ "	<td>" + (++n) + "</td>"
				+ "	<td>" + r.get("reference_no") + "</td>"
				+ "	<td>" + Encode.forHtml(r.get("vendor")) + "</td>"
				+ "	<td>" + r.get("area") + "</td>"
				+ "	<td>" + r.get("job_type") + "</td>"
				+ "	<td>" + (r.get("stock") == null ? "-" : r.get("stock")) + "</td>"
				+ "	<td>" + Encode.forHtml(r.get("creator")) + "</td>"
				+ "	<td>" + r.get("sent_date") + "</td>"
				+ "	<td>" + r.get("completed_date") + "</td>"
				+ "	<td>" + r.get("sla") + "</td>"
				+ "	<td>" + (r.get("reschedule_date") == null ? "-" : r.get("reschedule_date")) + "</td>"
				+ "	<td>" + r.get("status") + "</td>"
				+ "	<td>" + (r.get("wireless_stock") == null ? "-" : r.get("wireless_stock")) + "</td>"
				+ "	<td>" + r.get("debit") + "</td>"
				+ "	<td>" + Encode.forHtml(r.get("merchant_name")) + "</td>"
				+ "	<td>" + (addrObj.get(0) == null ? "-" : addrObj.get(0).toString()) + "</td>"
				+ "	<td>" + (addrObj.get(1) == null ? "-" : addrObj.get(1).toString()) + "</td>"
				+ "	<td>" + (addrObj.get(2) == null ? "-" : addrObj.get(2).toString()) + "</td>"
				+ "	<td>" + (r.get("amex_pos") == null ? "-" : r.get("amex_pos")) + "</td>"
				+ "	<td>" + (r.get("amex_moto") == null ? "-" : r.get("amex_moto")) + "</td>"
				+ "	<td>" + (partnerObj.get("DINERS").toString().equals("") ? "-" : partnerObj.get("DINERS").toString()) + "</td>"
				+ "	<td>" + (partnerObj.get("GENTING").toString().equals("") ? "-" : partnerObj.get("GENTING").toString()) + "</td>"
				+ "	<td>" + (partnerObj.get("AEON").toString().equals("") ? "-" : partnerObj.get("AEON").toString()) + "</td>"
				+ "	<td>" + (r.get("pos_mid") == null ? "-" : r.get("pos_mid")) + "</td>"
				+ "	<td>" + (r.get("pos_tid") == null ? "-" : r.get("pos_tid")) + "</td>";
			
			JSONObject tempObj = (JSONObject) ezpayObj.get("E3");
			html += "<td>" + (tempObj.get("tid_no").toString().equals("") ? "-" : tempObj.get("tid_no").toString()) + "</td>";
			html += "<td>" + (tempObj.get("mid_no").toString().equals("") ? "-" : tempObj.get("mid_no").toString()) + "</td>";
				
			tempObj = (JSONObject) ezpayObj.get("E6");
			html += "<td>" + (tempObj.get("tid_no").toString().equals("") ? "-" : tempObj.get("tid_no").toString()) + "</td>";
			html += "<td>" + (tempObj.get("mid_no").toString().equals("") ? "-" : tempObj.get("mid_no").toString()) + "</td>";
				
			tempObj = (JSONObject) ezpayObj.get("E9");
			html += "<td>" + (tempObj.get("tid_no").toString().equals("") ? "-" : tempObj.get("tid_no").toString()) + "</td>";
			html += "<td>" + (tempObj.get("mid_no").toString().equals("") ? "-" : tempObj.get("mid_no").toString()) + "</td>";
				
			tempObj = (JSONObject) ezpayObj.get("E12");
			html += "<td>" + (tempObj.get("tid_no").toString().equals("") ? "-" : tempObj.get("tid_no").toString()) + "</td>";
			html += "<td>" + (tempObj.get("mid_no").toString().equals("") ? "-" : tempObj.get("mid_no").toString()) + "</td>";
				
			tempObj = (JSONObject) ezpayObj.get("E18");
			html += "<td>" + (tempObj.get("tid_no").toString().equals("") ? "-" : tempObj.get("tid_no").toString()) + "</td>";
			html += "<td>" + (tempObj.get("mid_no").toString().equals("") ? "-" : tempObj.get("mid_no").toString()) + "</td>";
				
			tempObj = (JSONObject) ezpayObj.get("E24");
			html += "<td>" + (tempObj.get("tid_no").toString().equals("") ? "-" : tempObj.get("tid_no").toString()) + "</td>";
			html += "<td>" + (tempObj.get("mid_no").toString().equals("") ? "-" : tempObj.get("mid_no").toString()) + "</td>";
				
			tempObj = (JSONObject) ezpayObj.get("E30");
			html += "<td>" + (tempObj.get("tid_no").toString().equals("") ? "-" : tempObj.get("tid_no").toString()) + "</td>";
			html += "<td>" + (tempObj.get("mid_no").toString().equals("") ? "-" : tempObj.get("mid_no").toString()) + "</td>";
				
			tempObj = (JSONObject) ezpayObj.get("E36");
			html += "<td>" + (tempObj.get("tid_no").toString().equals("") ? "-" : tempObj.get("tid_no").toString()) + "</td>";
			html += "<td>" + (tempObj.get("mid_no").toString().equals("") ? "-" : tempObj.get("mid_no").toString()) + "</td>";
				
			tempObj = (JSONObject) ezpayAmexObj.get("E3");
			html += "<td>" + (tempObj.get("tid_no").toString().equals("") ? "-" : tempObj.get("tid_no").toString()) + "</td>";
			html += "<td>" + (tempObj.get("mid_no").toString().equals("") ? "-" : tempObj.get("mid_no").toString()) + "</td>";
				
			tempObj = (JSONObject) ezpayAmexObj.get("E6");
			html += "<td>" + (tempObj.get("tid_no").toString().equals("") ? "-" : tempObj.get("tid_no").toString()) + "</td>";
			html += "<td>" + (tempObj.get("mid_no").toString().equals("") ? "-" : tempObj.get("mid_no").toString()) + "</td>";
				
			tempObj = (JSONObject) ezpayAmexObj.get("E9");
			html += "<td>" + (tempObj.get("tid_no").toString().equals("") ? "-" : tempObj.get("tid_no").toString()) + "</td>";
			html += "<td>" + (tempObj.get("mid_no").toString().equals("") ? "-" : tempObj.get("mid_no").toString()) + "</td>";
				
			tempObj = (JSONObject) ezpayAmexObj.get("E12");
			html += "<td>" + (tempObj.get("tid_no").toString().equals("") ? "-" : tempObj.get("tid_no").toString()) + "</td>";
			html += "<td>" + (tempObj.get("mid_no").toString().equals("") ? "-" : tempObj.get("mid_no").toString()) + "</td>";
				
			tempObj = (JSONObject) ezpayAmexObj.get("E18");
			html += "<td>" + (tempObj.get("tid_no").toString().equals("") ? "-" : tempObj.get("tid_no").toString()) + "</td>";
			html += "<td>" + (tempObj.get("mid_no").toString().equals("") ? "-" : tempObj.get("mid_no").toString()) + "</td>";
				
			tempObj = (JSONObject) ezpayAmexObj.get("E24");
			html += "<td>" + (tempObj.get("tid_no").toString().equals("") ? "-" : tempObj.get("tid_no").toString()) + "</td>";
			html += "<td>" + (tempObj.get("mid_no").toString().equals("") ? "-" : tempObj.get("mid_no").toString()) + "</td>";
				
			tempObj = (JSONObject) ezpayAmexObj.get("E30");
			html += "<td>" + (tempObj.get("tid_no").toString().equals("") ? "-" : tempObj.get("tid_no").toString()) + "</td>";
			html += "<td>" + (tempObj.get("mid_no").toString().equals("") ? "-" : tempObj.get("mid_no").toString()) + "</td>";
				
			tempObj = (JSONObject) ezpayAmexObj.get("E36");
			html += "<td>" + (tempObj.get("tid_no").toString().equals("") ? "-" : tempObj.get("tid_no").toString()) + "</td>";
			html += "<td>" + (tempObj.get("mid_no").toString().equals("") ? "-" : tempObj.get("mid_no").toString()) + "</td>";
			
			html += "	<td>" + (acceptanceObj.get("UPI").toString().equals("") ? "-" : acceptanceObj.get("UPI").toString()) + "</td>"
					+ "	<td>" + (acceptanceObj.get("ORS").toString().equals("") ? "-" : acceptanceObj.get("ORS").toString()) + "</td>"
					+ "	<td>" + (acceptanceObj.get("DCC").toString().equals("") ? "-" : acceptanceObj.get("DCC").toString()) + "</td>"
					+ "	<td>" + (acceptanceObj.get("WAVE").toString().equals("") ? "-" : acceptanceObj.get("WAVE").toString()) + "</td>";
					
			html += "	<td>" + (otherObj.get("ECR Cable").toString().equals("") ? "-" : otherObj.get("ECR Cable").toString()) + "</td>"
					+ "	<td>" + (otherObj.get("Cash Advance").toString().equals("") ? "-" : otherObj.get("Cash Advance").toString()) + "</td>"
					+ "	<td>" + (otherObj.get("Cash Back").toString().equals("") ? "-" : otherObj.get("Cash Back").toString()) + "</td>";
			
			html += "	<td>" + (hotelFunctionObj.get("Card Verify").toString().equals("") ? "-" : hotelFunctionObj.get("Card Verify").toString()) + "</td>"
					+ "	<td>" + (hotelFunctionObj.get("Offline").toString().equals("") ? "-" : hotelFunctionObj.get("Offline").toString()) + "</td>"
					+ "	<td>" + (hotelFunctionObj.get("Manual Key-In").toString().equals("") ? "-" : hotelFunctionObj.get("Manual Key-In").toString()) + "</td>"
					+ "	<td>" + (hotelFunctionObj.get("Tips").toString().equals("") ? "-" : hotelFunctionObj.get("Tips").toString()) + "</td>"
					+ "	<td>" + (hotelFunctionObj.get("Refund").toString().equals("") ? "-" : hotelFunctionObj.get("Refund").toString()) + "</td>";
					
			html += "<td>" + (r.get("remark") == null ? "-" : r.get("remark")) + "</td>"
				+ "</tr>";
			
			out.print(html);
		}
		%>
		</tbody></table>
		</div>
		
	</div>
</div>

<!-- Footer -->
<%@ include file="/jsp/common/Footer.jsp" %>	
<!-- End Footer -->


</body>
</html>